1. /* slflrand.cpp by K.Tsuru */
  2. // function ID = 2003
  3. /***************************************************************************
  4. SLong and SInteger classes
  5. It provides a random number with the radix (= DRADIX or BRADIX).
  6. radix = DRADIX in default.
  7. When size = 0 it is taken as minArraySize.
  8. If 'size' has a value which is greater than the maximum size it is adjusted
  9. to the maximum one.
  10. ***************************************************************************/
  11. #ifndef SN_H
  12. #include "sn.h"
  13. #endif
  14. #include <time.h>
  15. SLong LRand(uint size, fType radix){
  16. SNumber::NumberType tp = (radix > DRADIX) ? SNumber::BIN_INT : SNumber::DEC_INT;
  17. fType rdx = (radix > DRADIX) ? BRADIX : DRADIX;
  18. uint max_sz = SNManager::SNMaxSize(tp);
  19. if(!size) size = minArraySize;
  20. else if(size > max_sz) size = max_sz;
  21. SLong result(tp, size);
  22. FigBlock a(size);
  23. fType* p = a.Elements();
  24. time_t t;
  25. static uint seed = (uint)time(&t);
  26. srand(seed);
  27. for(uint j = 0; j < size ; j++) p[j] = fType( rand() % (int)rdx );
  28. a.clear(size);
  29. seed = (uint)rand(); // set new seed for next call.
  30. result.SetFigBlock(a, 1); // result.CheckArray(); done
  31. return result;
  32. }

slflrand.cpp : last modifiled at 2017/03/17 11:10:48(1,186 bytes)
created at 2017/10/07 10:26:49
The creation time of this html file is 2017/11/09 14:52:03 (Thu Nov 09 14:52:03 2017).